<?php

class dayworkAction extends CommonAction
{
	public function index()
	{
		$dayWorkView = D("dayworkView");
		$daywork_list=$dayWorkView->select();
		$this->daywork_list=$daywork_list;
		$this->display();	
	}
	
    public  function  add()
    {
    	$dayworkType=M("dayworktype");
    	$typelist=$dayworkType->select();
    	$this->typelist=$typelist;
        $this->display();  
    }
    
    public function save()
    {
        import("ORG.Net.UploadFile");
        $upload = new UploadFile();
        $upload->autoSub = true; //子目录
	    $upload->subType   =  'date';
	    $upload->savePath = './Uploads/DayWork/';  //设置附件上传目录
        
        if(!empty($_FILES['thumb'])) 
	    {
	        $upload->maxSize  = 3145728 ;// 设置附件上传大小
    	    $upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
    	        	    
	        $thumbinfo =  $upload->uploadOne($_FILES['thumb']);
	        if($thumbinfo){ // 保存附件信息
	            $data['thumb'] = $thumbinfo[0]['savename'];        
	         }else{ // 上传错误	 
	           $this->error($upload->getErrorMsg());
	         }
	     }
    	 else 
	     {
	         $this->error("请选择上传图片");
	     }
	     
	     if(!empty($_FILES['content']))
	     {
	     	$upload->allowExts  =array('txt','doc','docx','xls','ppt','pdf','rar','zip');
	        $contentinfo =  $upload->uploadOne($_FILES['content']);
	        if($contentinfo){ // 保存附件信息
	            $data['content'] = $contentinfo[0]['savename'];        
	         }else{ // 上传错误	 
	           $this->error($upload->getErrorMsg());
	         }
	     }
    	 else 
	     {
	         $this->error("请选择上传附件");
	     }
		 $model = D('daywork');
		 //保存当前数据对象
		 $data['create_time'] = NOW_TIME;
		 $data['classid']=I('post.classid');
		 $data['title']=I('post.title');
		 $data["adduser"] = I('session.userid', 0);
		 $data["addtime"] = date("Y-m-d H:i:s");
		 $result=$model->add($data);
		 $this->assign("jumpUrl", U("daywork/index"));
		 $this->success("创建成功");
    }

    public function _empty()
    {
        //空操作
        $this->error("您访问的页面不存在！");
    }
}
?>